<?php
namespace app\demo_record\controller;

use think\Controller;
use app\demo_record\widget\MenuWidget;
use app\demo_record\widget\FormWidget;
use cmf\controller\HomeBaseController;
use cmf\controller\BaseController;

class TestController extends BaseController
{
    /**
     * widget控件有两种使用方式
     * 一种是调用单独的模板，使用fetch方法
     * 一种是绑定到已有模板，使用视图的assign方法
     */
    protected function getMenu()
    {
        $menu=new MenuWidget;
        return $menu->insertItems([
            ["title"=>"测试","active"=>"1","href"=>"http://www.baidu.com"],
            ["title"=>"测试2","href"=>"demo_record/test/menu1","type"=>"path","target"=>"_blank"]
        ])
        ->insertItemTitles(["分类一","分类二"])
        ->insertItems([["title"=>"测试3","href"=>"demo_record/test/menu1","type"=>"path","target"=>"_blank","flag"=>"red"]]);
    }
    public function showBlockMenu()
    {
        $this->assign("widget",$this->getMenu()->fetch());
        return $this->fetch("null");
    }
    public function showInlineMenu()
    {
        $this->assign("menu",$this->getMenu());
        return $this->fetch("inline_menu");
    }
}
